package service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import dao.UserDAO;
import entity.User;
import service.UserService;

@Component
public class UserServiceImpl implements UserService{

	@Autowired
	private UserDAO dao;
	
	@Override
	public void insertUser(User u) {
		String username=u.getUname();
		if(dao.selectUsername(username)==null){
			//用户名没有被占用
			dao.insertUser(u);
		}else{
			//用户名占用了
			throw new RuntimeException("用户名已经存在，不能注册");
		}
		
		                               
	}

	@Override
	public User selectUser(String username, String password) {                                                
		return dao.selectUser(username, password);
	}

}
